/**
 * Project Reactor
 */


#ifndef _EVENTLOOP_H
#define _EVENTLOOP_H
#include "Acceptor.h"
#include "TcpConnection.h"
#include <vector>
#include <map>
#include <memory>

using std::shared_ptr;
using std::vector;
using std::map;

using TcpConnectionPtr = shared_ptr<TcpConnection>;

#define MAX_EVTLIST_SIZE 1024

class EventLoop {
public: 
    
/**
 * @param accept
 */
EventLoop(Acceptor & acceptor);
    
~EventLoop();
    
int createEpollFd();
    
/**
 * @param fd
 */
void addEpollReadFd(int fd);
    
/**
 * @param fd
 */
void delEpollReadFd(int fd);
    
void m_epoll_wait();
    
void handleNewConnection();
    
/**
 * @param fd
 */
void handleMessage(int fd);
    
void loop();
    
void unloop();
    
void waitEpollFd();
private: 
    int m_epfd;
    vector<struct epoll_event> m_evtList;
    // struct epoll_event *m_evtList;
    Acceptor & m_acceptor;
    map<int,shared_ptr<TcpConnection>> m_connMap;
    bool m_isLooping;
};

#endif //_EVENTLOOP_H